import { create } from 'zustand'
import { persist } from 'zustand/middleware'

export type ThemeMode = 'soft' | 'vibrant'

type ThemeState = {
  mode: ThemeMode
  autoMode: boolean
  showTexture: boolean
  glowLevel: 'low' | 'medium' | 'high'
  palette: [string, string, string, string] // r,g,b tuples
  setMode: (mode: ThemeMode) => void
  setAutoMode: (auto: boolean) => void
  setShowTexture: (val: boolean) => void
  setGlowLevel: (lvl: 'low' | 'medium' | 'high') => void
  setPalette: (p: [string, string, string, string]) => void
}

export const useThemeStore = create<ThemeState>()(
  persist(
    (set) => ({
      mode: 'vibrant',
      autoMode: true,
      showTexture: true,
      glowLevel: 'medium',
      // 更沉稳、对比更好的活力配色（Sky/Indigo/Emerald/Orange）
      palette: ['56,189,248', '99,102,241', '34,197,94', '251,146,60'],
      setMode: (mode) => set({ mode }),
      setAutoMode: (auto) => set({ autoMode: auto }),
      setShowTexture: (val) => set({ showTexture: val }),
      setGlowLevel: (lvl) => set({ glowLevel: lvl }),
      setPalette: (p) => set({ palette: p }),
    }),
    { name: 'love-notes-theme' },
  ),
)

export default useThemeStore
